home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / nShell-Pro.sit / nShell-Pro / doc / nShell™ User's Guide.rsrc / TEXT_137.txt < prev    next >
Text File  |  1994-12-27  |  5KB  |  130 lines

  1.  
  2. Drag and Drop
  3.  
  4. Two methods of drag and drop access have been added to the nShell.  The first, using text files, allows the user to quickly start and run scripts within the nShell application.  The second method, using a separate engine, allows scripts to be converted to stand alone drag and drop applications.  This second method allows files, folders and disks to be dropped on scripts and accessed as standard script parameters.
  5.  
  6. Either kind of script may also be run by typing its name on the command line.  The script would then be run in the existing window.
  7.  
  8. System Variables
  9.  
  10. On startup, both kinds of scripts search out the nShell application and set their paths based upon that directory.  These paths may be modified by the script.  The initial values are:
  11.  
  12. PWD = "script directory"
  13. HOME = "nShell application directory"
  14. PATH = ":/nShell application directory:bin"
  15. TMP = "nShell application directory:tmp"
  16.  
  17. TEXT scripts
  18.  
  19. You may write TEXT scripts using your any text editor, including the TeachText or SimpleText editor that came with your Macintosh.  The easiest way to run a TEXT script is to drop it on the nShell application.  A new shell window will be opened, and the script will be run.  When the script completes, a prompt is provided to the user.
  20.  
  21. To make the script clickable, change the file's creator to 'NSHA':
  22.  
  23. chattr my_script -c NSHA
  24.  
  25. The Droplet Engine
  26.  
  27. The advantage of using a drag and drop engine, is that it allows files, folders and disks to be dropped on scripts and accessed as standard script parameters.
  28.  
  29. Droplets terminate automatically when their scripts complete.
  30.  
  31. Writing a Droplet
  32.  
  33. Make a copy of the "nShell邃「 droplet" engine.  You can use the finder "Duplicate" function, or the nShell "cp" command.  Give this copy of the drag and drop template a unique name.
  34.  
  35. Method 1 - Direct Editing
  36.  
  37. Drag your new icon onto a BBEdit icon, and type in your script.  Close the file and you're done.
  38.  
  39. NOTE:  If you use "Save As" within BBEdit, a new text file will be created, and the executable portion of the droplet will not be copied.  
  40.  
  41. Method 2 - Appending a file
  42.  
  43. If you have an existing script file which you would like to make into a drag and drop application, you can 'cat' the file onto a copy of the "nShell邃「 droplet":
  44.  
  45. cat my_script >> template_copy
  46.  
  47. and you're done.
  48.  
  49. NOTE:  Never use the ">" operator, as this will delete and replace the target with a new TEXT file.
  50.  
  51. Parameters
  52.  
  53. The normal script parameters $#, $0...$n will be set up with any items dropped onto the application.  Specifically:
  54.  
  55. $# = The number of parameters (1 = script only, 2 = script + 1 param, etc.)
  56. $0 = The name of the script (not a full pathname)
  57. $1 = The full pathname of the first dropped item
  58. $2 = The full pathname of the second dropped item
  59. ...
  60.  
  61. The parameters may be files, folders, or disks but are always represented as pathnames.  Remember to use quotes around these variables, as in
  62.  
  63. chattr "$1" -c 'NSHA'
  64.  
  65. In nShell-Pro, a while-shift loop may be used to process a large number of dropped files:
  66.  
  67. #
  68. # Set all text files to Creator = 'NSHA'
  69. #
  70. echo "working..."
  71. while shift do
  72.     ls "$0" -l | read crea type extra
  73.     if .eq. $type TEXT then echo ' ' ; chattr "$0" -c NSHA endif
  74. done
  75.  
  76. Limitations:  The total length of all dropped pathnames may not exceed 10k characters.  Beyond this input is ignored.  Only those files dropped on the application as it is opened are set as parameters.  Anything dropped on the script after it is running is ignored (the finder is given an errAEEventNotHandled).
  77.  
  78. Memory
  79.  
  80. The default memory size for droplets is 250k. That should be enough for quite a lot of processing.  If you think you are going to need it, bump the memory.  The nShell and the droplet engine start complaining about low memory when 80k is left.
  81.  
  82. Hints
  83.  
  84. Hint #1
  85.  
  86. If you're not sure what's going on with a drag an drop script, add
  87.  
  88. env
  89. echo ' '
  90. echo 'Press <Return> to continue...'
  91. echo ' '
  92. read foo
  93.  
  94. as the first lines.  That'll tell you what your dropped files ended up looking like. 
  95.  
  96. And if you don't want to fall off the end of the script right away, use 'delay 5' or 'read foo' or something as the last line.
  97.  
  98. Hint #2
  99.  
  100. To run a TEXT script in a new window, you could double-click it in the Finder or type:
  101.  
  102. odoc my_script
  103.  
  104. To run a droplet as a stand-alone application,  you could double-click it in the Finder or launch it:
  105.  
  106. launch my_droplet
  107.  
  108. Or use "odoc" to send it a parameter:
  109.  
  110. odoc my_parameter my_droplet
  111.  
  112. Hint #3
  113.  
  114. Any script can run any other script.  So create a drag and drop application containing the line
  115.  
  116. "$1"
  117.  
  118. and you have a program that will run any nShell script dropped on it and then terminate.
  119.  
  120. In nShell-Pro, a while-shift loop could be used to execute all dropped scripts:
  121.  
  122. while shift do
  123.     ls "$0" -l | read crea type extra
  124.     if .eq. $crea NSHA then
  125.         if .eq. $type TEXT then
  126.             "$0"
  127.         endif
  128.     endif
  129. done
  130.